package com.liuhongwei.test.builder.strategy.impl;
import com.liuhongwei.test.bean.FieldInfo;
import com.liuhongwei.test.bean.TableInfo;
import com.liuhongwei.test.builder.BuildExtendMapperXml;
import com.liuhongwei.test.builder.strategy.inf.MapperXmlStrategy;

import java.io.BufferedWriter;
import java.io.IOException;

/**
 * 通用查询结果列
 */
public class XmlFieldColumnListImpl implements MapperXmlStrategy {

    @Override
    public void generateMapperXml(TableInfo tableInfo, BufferedWriter bw) throws IOException {
        bw.write("\t<!--通用查询结果列-->\n");
        StringBuilder sb = new StringBuilder();
        for (FieldInfo field : tableInfo.getFieldList()) {
            sb.append(field.getFieldName()).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        bw.write("\t<sql id=\"" + BuildExtendMapperXml.BASE_COLUMN_LIST + "\">\n");
        bw.write("\t\t" + sb + "\n");
        bw.write("\t</sql>\n\n");
    }
}
